/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LugaresEmPe.java
 *
 * Created on 26/06/2012, 17:59:52
 */
package View;

import Controller.Controller;
import Model.Cargo;
import Model.Evento;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

/**
 *
 * @author lcc
 */
public class LugaresEmPe extends javax.swing.JFrame {

    private Controller controller;
    private Evento evento;

    /**
     * Creates new form LugaresEmPe
     */
    public LugaresEmPe(Evento evento) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 3, screenSize.height / 3);
        this.evento = evento;
        controller = Controller.getInstance();
        initComponents();
        lugaresPistaVIP.setText("Ingressos Disponíveis: " + evento.getQtdIngressosNaoVendidos());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pistaVip = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        confirmarVIP = new javax.swing.JButton();
        pistaNormal = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        confirmarNormal = new javax.swing.JButton();
        camarote = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        confirmarCamarote = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        voltarButton = new javax.swing.JToggleButton();
        lugaresPistaVIP = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pistaVip.setBackground(new java.awt.Color(255, 255, 120));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 15));
        jLabel4.setText("Pista VIP");

        confirmarVIP.setText("Confirmar");
        confirmarVIP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarVIPActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pistaVipLayout = new javax.swing.GroupLayout(pistaVip);
        pistaVip.setLayout(pistaVipLayout);
        pistaVipLayout.setHorizontalGroup(
            pistaVipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pistaVipLayout.createSequentialGroup()
                .addGroup(pistaVipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pistaVipLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4))
                    .addGroup(pistaVipLayout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(confirmarVIP, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(119, Short.MAX_VALUE))
        );
        pistaVipLayout.setVerticalGroup(
            pistaVipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pistaVipLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(confirmarVIP, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                .addContainerGap())
        );

        pistaNormal.setBackground(new java.awt.Color(120, 255, 120));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 15));
        jLabel5.setText("Pista Normal");

        confirmarNormal.setText("Confirmar");
        confirmarNormal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarNormalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pistaNormalLayout = new javax.swing.GroupLayout(pistaNormal);
        pistaNormal.setLayout(pistaNormalLayout);
        pistaNormalLayout.setHorizontalGroup(
            pistaNormalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pistaNormalLayout.createSequentialGroup()
                .addGroup(pistaNormalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pistaNormalLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5))
                    .addGroup(pistaNormalLayout.createSequentialGroup()
                        .addGap(127, 127, 127)
                        .addComponent(confirmarNormal, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(117, Short.MAX_VALUE))
        );
        pistaNormalLayout.setVerticalGroup(
            pistaNormalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pistaNormalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(confirmarNormal, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        camarote.setBackground(new java.awt.Color(255, 120, 120));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 15));
        jLabel2.setText("Camarote");

        confirmarCamarote.setText("Confirmar");
        confirmarCamarote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarCamaroteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout camaroteLayout = new javax.swing.GroupLayout(camarote);
        camarote.setLayout(camaroteLayout);
        camaroteLayout.setHorizontalGroup(
            camaroteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(camaroteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(52, 52, 52)
                .addComponent(confirmarCamarote, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(117, Short.MAX_VALUE))
        );
        camaroteLayout.setVerticalGroup(
            camaroteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(camaroteLayout.createSequentialGroup()
                .addGroup(camaroteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(camaroteLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(camaroteLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(confirmarCamarote, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel7.setText("Comprar Ingresso");

        voltarButton.setText("Voltar");
        voltarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarButtonActionPerformed(evt);
            }
        });

        lugaresPistaVIP.setFont(new java.awt.Font("Tahoma", 0, 15));
        lugaresPistaVIP.setText("Lugares:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(pistaNormal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(pistaVip, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(camarote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(voltarButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(206, 206, 206)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(lugaresPistaVIP))
                            .addComponent(jLabel7))))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lugaresPistaVIP)
                .addGap(10, 10, 10)
                .addComponent(pistaVip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pistaNormal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(camarote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addComponent(voltarButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void confirmarVIPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarVIPActionPerformed
        // TODO add your handling code here:
        if (!controller.vendeIngressoEmPe('v', evento)) {
            JOptionPane.showMessageDialog(null, "Setor lotado! Por favor, escolha outro.", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Compra efetuada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            lugaresPistaVIP.setText("Ingressos Disponíveis: " + evento.getQtdIngressosNaoVendidos());
//            LugaresEmPe lp = new LugaresEmPe(evento);
//            lp.setVisible(true);
//            this.setVisible(false);
        }
    }//GEN-LAST:event_confirmarVIPActionPerformed

    private void confirmarNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarNormalActionPerformed
        // TODO add your handling code here:
        if (!controller.vendeIngressoEmPe('n', evento)) {
            JOptionPane.showMessageDialog(null, "Setor lotado! Por favor, escolha outro.", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Compra efetuada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            lugaresPistaVIP.setText("Ingressos Disponíveis: " + evento.getQtdIngressosNaoVendidos());
//            LugaresEmPe lp = new LugaresEmPe(evento);
//            lp.setVisible(true);
//            this.setVisible(false);
        }
    }//GEN-LAST:event_confirmarNormalActionPerformed

    private void confirmarCamaroteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarCamaroteActionPerformed
        // TODO add your handling code here:
        if (!controller.vendeIngressoEmPe('c', evento)) {
            JOptionPane.showMessageDialog(null, "Setor lotado! Por favor, escolha outro.", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Compra efetuada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            lugaresPistaVIP.setText("Ingressos Disponíveis: " + evento.getQtdIngressosNaoVendidos());
//            LugaresEmPe lp = new LugaresEmPe(evento);
//            lp.setVisible(true);
//            this.setVisible(false);
        }
    }//GEN-LAST:event_confirmarCamaroteActionPerformed

    private void voltarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarButtonActionPerformed
        if (controller.getCargo() == Cargo.GERENTE) {
            VerEventoGerente veg = new VerEventoGerente(evento);
            veg.setVisible(true);
            this.setVisible(false);
        } else {
            VerEventoBilheteria veb = new VerEventoBilheteria(evento);
            veb.setVisible(true);
            this.setVisible(false);
        }
    }//GEN-LAST:event_voltarButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new LugaresEmPe(new Evento()).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel camarote;
    private javax.swing.JButton confirmarCamarote;
    private javax.swing.JButton confirmarNormal;
    private javax.swing.JButton confirmarVIP;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel lugaresPistaVIP;
    private javax.swing.JPanel pistaNormal;
    private javax.swing.JPanel pistaVip;
    private javax.swing.JToggleButton voltarButton;
    // End of variables declaration//GEN-END:variables
}
